package com.seafwg.config;

import com.seafwg.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author seafwg
 * @Date 2022/3/23 10:08 上午
 * @Version 1.0
 * @description xxx
 */

@Configuration
public class MyComponentConfig implements WebMvcConfigurer {

    /**
     * 注册拦截对象
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String path[] = {"/user/**"};
        String excludePath[] = {"/user/login"};

        // 要注入的对象
        LoginInterceptor loginInterceptor = new LoginInterceptor();
        // 添加注入的对象
        InterceptorRegistration addInterceptor = registry.addInterceptor(loginInterceptor);
        // 添加拦截的路径
        addInterceptor.addPathPatterns(path);
        // 添加排除拦截的路径
        addInterceptor.excludePathPatterns(excludePath);
    }
}
